﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace bmiCalculationMiniprojMethod
{
    class RunProgram
    {
        public static double calcBMI(double weightKg, double heightCm ) // calculates the body mass index given weight in kiloggrams and height in centimeters
        {
            double heightM = heightCm / 100;  // the bmi formulae actually uses height in meters  1cm == 0.01 m
            double bmi = weightKg / (heightM * heightM);  // bmi is weight / height^2  units kg/m^2
            bmi = Math.Round(bmi, 2, MidpointRounding.AwayFromZero); // round the double value  to two decimal points
            return bmi;
        }

        static void Main(string[] args)
        {
            Console.WriteLine("DEVELOP METHOD TO CALCULATE BODY MASS INDEX GIVEN WEIGHT AND HEIGHT");
            Console.WriteLine();
            try
            {
                bool anotherCalc = true;
                while (anotherCalc == true)
                {

                    Console.Write("Enter Childs Weight in Kg:- ");
                    double childsWeight =  double.Parse(Console.ReadLine());

                    Console.Write("Enter Childs Height in Centimerers:- ");
                    double childsHeight = double.Parse(Console.ReadLine());

                    double bmi = calcBMI(childsWeight, childsHeight);

                    Console.WriteLine("For a Childs weight of {0} and height of {1} the Body Mass Index would be {2}", childsWeight, childsHeight, bmi);

                    Console.WriteLine();
                    Console.Write("To run another Body Mass Index calculation just type 'y':- ");
                    string s = Console.ReadLine().ToLower();
                    if( s != "y")
                    {
                        anotherCalc = false;
                    }

                }
            } // close of try block
            catch(Exception e)
            {
                Console.WriteLine("Caught an Exception! {0}", e.Message);
            } // close of catch block

            Console.WriteLine();
            Console.Write("Press ENTER to Exit!");
            Console.ReadKey();
        } // close main method

    } // close class runprogram

}// close of namespace
